package com.sxun.launcher.dialog;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface.OnCancelListener;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.iiordanov.bVNC.R;
//import com.sxun.launcher.service.ServiceManager;

public class UploadDialog  extends AlertDialog {

	 
    private AlertDialog dialog;
    // 显示动画的组件
    private ImageView imgDance;
    // Frame动画
    private AnimationDrawable animDance;
      
    private TextView contentTextView;
    private String message; 
	private Context context;
    
    public void SetDialog(AlertDialog dialog) {
		this.dialog = dialog;
	}

	public UploadDialog(Context context) {
		super(context);
	}

	public UploadDialog(Context context,  String message) {
		super(context); 
		this.context = context;
		this.message=message;
	}

	public UploadDialog(Context context, boolean cancelable,
			OnCancelListener cancelListener) {
		super(context, cancelable, cancelListener);
	}
    /** 
     * @see Activity#onCreate(Bundle)
     */
    public void onCreate(Bundle cycle) {
        super.onCreate(cycle);
        super.setContentView(R.layout.dialog_upload);
        //this.dialog.setCanceledOnTouchOutside(false); 
        //this.setCanceledOnTouchOutside(false);  
        
        contentTextView=(TextView)this.findViewById(R.id.conten_textview);
        
        if(message!=null &&!"".equals(message)){
        	contentTextView.setText(message);
        	contentTextView.setTextColor(getContext().getResources().getColor(R.color.white));
        }else{
        	LinearLayout layoutcenter=(LinearLayout)this.findViewById(R.id.layout_center);
        	layoutcenter.setLayoutParams(new LinearLayout.LayoutParams(70, 50));
        }
        // 实例化组件
        this.imgDance = (ImageView)super.findViewById(R.id.ImgDance);
          
        // 获得背景（6个图片形成的动画）
        this.animDance = (AnimationDrawable)this.imgDance.getBackground();
        
        this.animDance.start();
        //this.animDance.stop();
    }
    
	public void setCenter() {
		Window window = this.getWindow(); // 得到对话框的窗口．
		WindowManager.LayoutParams wl = window.getAttributes(); 
		// wl.alpha=0.6f;//这句设置了对话框的透明度
		wl.gravity = Gravity.CENTER;
		window.setAttributes(wl);

	}
      
	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
	//	ServiceManager.startMyStart=false;
		dialog.setCanceledOnTouchOutside(false);
	}
}
